package com.example.pmxt.modules.cooperation;

import com.example.pmxt.common.ReturnResult;
import com.example.pmxt.domain.Cooperation;
import com.example.pmxt.domain.Dict;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/cooperation")
public class CooperationController {

    private final CooperationService cooperationService;

    public CooperationController(@Autowired CooperationService cooperationService){
        this.cooperationService = cooperationService;
    }

    @GetMapping("/getAll")//查询全部
    public ReturnResult selectAll(){
        return ReturnResult.buildSuccessResult(cooperationService.selectAll());
    }

    @PostMapping("/addcooperation")  //新增合作机构
    public ReturnResult insert( @RequestBody @Validated Cooperation cooperation) {
        return ReturnResult.buildSuccessResult(cooperationService.insert(cooperation));
    }

    @DeleteMapping("/{id}")//按ID删除合作机构
    public ReturnResult deleteById(@PathVariable Integer id) {
        return ReturnResult.buildSuccessResult(cooperationService.removeById(id));
    }

//    @PostMapping("/update") //修改指定ID的合作机构
//    public ReturnResult updateById(@Validated @RequestBody  Cooperation cooperation ) {
//        return ReturnResult.buildSuccessResult(cooperationService.update(cooperation));
//    }

    @PutMapping("/update")
    public ReturnResult updateById(@Validated @RequestBody Cooperation cooperation ) {
        return ReturnResult.buildSuccessResult(cooperationService.updateById(cooperation));
    }

}


